package com.flux.ui.main;

import android.os.Bundle;

import com.common.bus.task.ICallBack;
import com.flux.models.bean.EventInfo;
import com.flux.models.bean.EventsRequest;
import com.flux.models.IDataModel;

import java.util.List;

/**
 * Created by cxlin007 on 2017/10/30.
 */

public class MainController implements MainConstant.Controller {

    private final MainConstant.View view;
    private final IDataModel dataModel;

    public MainController(MainConstant.View view, IDataModel dataModel) {
        this.view = view;
        this.view.setController(this);
        this.dataModel = dataModel;
    }

    @Override
    public void doOnCreate(Bundle savedInstanceState) {

    }

    @Override
    public void doOnPause() {

    }

    @Override
    public void doOnResume() {

    }

    @Override
    public void doOnDestroy() {

    }

    @Override
    public void fetchEvents() {
        EventsRequest request = new EventsRequest();
        request.page = "event_home";
        dataModel.fetchEvents(request, new ICallBack<List<EventInfo>>() {

            @Override
            public void onPreTraktCall() {
                view.showLoading();
            }

            @Override
            public void onSuccess(List<EventInfo> eventInfos) {
                view.showContent(eventInfos);
            }

            @Override
            public void onError(Exception e) {
                view.showError();
            }
        });
    }
}
